package ServerSide;
// This file contains material supporting section 3.7 of the textbook:
// "Object Oriented Software Engineering" and is issued under the open-source
// license found at www.lloseng.com 

import java.io.*;
import java.util.HashMap;
import java.util.Vector;

import ClientSide.*;
import Common.*;
import Common.BetweenCoursesToClass;

import GUI.*;



//import ocsf.server.ConnectionToClient;
//import ServerSide.*;
//import DBconnection.mysqlConnection;

/**
 * This class constructs the UI for a chat client.  It implements the
 * chat interface in order to activate the display() method.
 * Warning: Some of the code here is cloned in ServerConsole 
 *
 * @author Fran&ccedil;ois B&eacute;langer
 * @author Dr Timothy C. Lethbridge  
 * @author Dr Robert Lagani&egrave;re
 * @version July 2000
 */
public class ClientConsole implements ChatIF 
{
  //Class variables *************************************************
	public   HashMap<String,Object> arg;
  /**
   * The default port to connect on.
   */
  final public static int DEFAULT_PORT = 5555;
  
  //Instance variables **********************************************
  
  /**
   * The instance of the client that created this ConsoleChat.
   */
  ChatClient client;
  static Login lg;
  static UserStudent us;
  
  //Constructors ****************************************************

  /**
   * Constructs an instance of the ClientConsole UI.
   *
   * @param host The host to connect to.
   * @param port The port to connect on.
   */
  public ClientConsole(String host, int port) 
  {
    try 
    {
      client= new ChatClient(host, port, this);
      lg=null;
    } 
    catch(IOException exception) 
    {
      System.out.println("Error: Can't setup connection!"
                + " Terminating client.");
      System.exit(1);
    }
  }

  
  //Instance methods ************************************************
  
  /**
   * This method waits for input from the console.  Once it is 
   * received, it sends it to the client's message handler.
   */
  public void accept() 
  {
    try
    {
      BufferedReader fromConsole = 
        new BufferedReader(new InputStreamReader(System.in));
      String message;

      while (true) 
      {
        message = fromConsole.readLine();
        client.openConnection();
        client.handleMessageFromClientUI(message);
      }
    } 
    catch (Exception ex) 
    {
      System.out.println
        ("Unexpected error while reading from console!");
    }
  }

 /* public void accept(String msg)
  {
	  try {
		client.openConnection();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
      client.handleMessageFromClientUI(msg); 
  }*/
  /**
   * This method overrides the method in the ChatIF interface.  It
   * displays a message onto the screen.
   *
   * @param message The string to be displayed.
   */
  public void display(String message) //0-id,1-connection status,2-user type, 3-login status(ok\failed)
  {
	 String[] result=null;
	 System.out.println("\n> " + message);
   //System.out.println("> " + message);

  result=message.split(" ");
  if(result[3].equalsIgnoreCase("OK"))
  	{
	 // lg.UserType=result[2];
	  
	 // lg.LoginResult=result[3];
	 // 
	  System.out.println("\n" + result[3] );
	  
	  lg.setText(result[0]+" " + result[3] +" " + result[2]);
	
	 System.out.println("\n> " + message);

  	}
  if(result[3].equalsIgnoreCase("FAILED"))
  {
	 // lg.LoginResult=result[3];
	  lg.setText(result[0]+" " + result[3] +" " + result[2]);
	//  lg.setText("login failed");
	  System.out.println("\n" + result[3] );

  }
 
   if(result[0].equalsIgnoreCase("YearQuery"))
   {
	   lg.SetYears(result[1], result[2]);
	   System.out.println("\n" + result[1] + result[2]);
   }
  }

  public void updateCoursesInfoStudent(Object msg)
  {
	
	  Courses CoursesResult=new Courses();
	  Vector<String> years=new Vector<String>();
	  Vector<String> semesters=new Vector<String>();
	  Vector<String[]> result=(Vector<String[]>)msg;
	 
	  for (int i=1; i<result.size()-1; i++){
			String[] array = (String[])result.get(i);
			
		CoursesResult.lOfCourses.addElement(new Course(array[0],array[1],array[2],array[3],array[4],array[5]));
		if(!years.contains(array[3])) years.add(array[3]);
		if(!semesters.contains(array[2])) semesters.add(array[2]);
		
		}
	 
	 // for(int i=0;i<semesters.size();i++)  System.out.println("\n"+semesters.get(i) );
	 
	lg.setStudentCoursesData(CoursesResult,years,semesters);
  }
  
  public void updateChildrenToParent(Object msg)
  {
	  Vector<String> ids=new Vector<String>();
	  Vector<String[]> result=(Vector<String[]>)msg;
	  int count=0;
	  System.out.println("\n in updateChildrenToParent ");
	  for (int i=1; i<result.size(); i++){
			String[] array = (String[])result.get(i);
			ids.add(array[0]);
			
			count++;
	
	  }
	
	 lg.setChildrenToParent(ids,count);
	 /*for (int i=0; i<ids.size(); i++){
			String array =ids.get(i);
			this.client.handleMessageFromClientUI("PersonalDataForParent "+array);
		

	  }*/	
	
	  
  }
  public void updateChildDataToParent(Object msg)
  {
	  Vector<String[]> result=(Vector<String[]>)msg;
	  String[] array = (String[])result.get(1);
	  lg.SetStudentPdataForParent(array[0],array[1],array[2],array[3]);
  }
  public void updateStudentsDataToPrinciple(Object msg)
  {
	  Vector<String[]> result=(Vector<String[]>)msg;
	  String[] array = (String[])result.get(1);
	  lg.SetStudentPdataForPrinciple(array[0],array[1],array[2],array[3]);
  }
  public void updateChildrenCoursesToParent(Object msg)
  {
	  Courses CoursesResult=new Courses();
	  Vector<String> years=new Vector<String>();
	  Vector<String> semesters=new Vector<String>();
	  Vector<String[]> result=(Vector<String[]>)msg;
	  String sid;
	  for (int i=1; i<result.size()-1; i++){
			String[] array = (String[])result.get(i);//Cname, Cid, Semester, Year, Grade
			
		CoursesResult.lOfCourses.addElement(new Course(array[0],array[1],array[2],array[3],array[4],array[5]));
		if(!years.contains(array[3])) years.add(array[3]);
		if(!semesters.contains(array[2])) semesters.add(array[2]);
		//System.out.println("\n in updateCoursesInfoStudent sid is"+ array[0]+array[1]);
		
		}
	  String[] array = (String[])result.lastElement();
	 // System.out.println("\n in updateCoursesInfoStudent sid is"+ array[0]);
	  sid=array[0];
	  //String[] array = (String[])result.get(result.size());
	 for(int i=0;i<semesters.size();i++)  System.out.println("\n "+years.get(i) );
	// System.out.println("\n in updateCoursesInfoStudent sid is"+ array[0]);
	  System.out.println("\n in updateCoursesInfoStudent for parent ");
	lg.setChildrenCoursesToParent(sid,CoursesResult,years,semesters);
  }
  
  public void updateCoursesForPrinciple(Object msg)
  {
	  Courses CoursesResult=new Courses();
	  Vector<String> years=new Vector<String>();
	  Vector<String> semesters=new Vector<String>();
	  Vector<String[]> result=(Vector<String[]>)msg;
	  String sid;
	  for (int i=1; i<result.size()-1; i++){
			String[] array = (String[])result.get(i);
			
		CoursesResult.lOfCourses.addElement(new Course(array[0],array[1],array[2],array[3],array[4],array[5]));
		if(!years.contains(array[3])) years.add(array[3]);
		if(!semesters.contains(array[2])) semesters.add(array[2]);
		System.out.println("\n in updateCoursesInfoStudent sid is"+ array[0]+array[1]);
		
		}
	  String[] array = (String[])result.lastElement();
	  System.out.println("\n in updateCoursesInfoStudent sid is"+ array[0]);
	  sid=array[0];

	  System.out.println("\n in updateCoursesInfoStudent for principle ");
	  lg.setStudCoursesToPrinciple(sid, CoursesResult, years, semesters);
  }
  
  public void updateDoneStatus (Object msg)
  {
	Boolean b=(Boolean) msg;
	lg.SetDataStatusPrinciple(b);
  }
  public void updatePDataStudent (Object msg)
  {
	  Vector<String[]> result=(Vector<String[]>)msg;
	  String[] array = (String[])result.get(1);
	  lg.SetStudentPdata(array[1],array[2],array[3]);
	  System.out.println("\n in SetPdataStudent "+array[1]+" "+array[2]+" "+array[3] );
}
  public void updateClassesAdmin(Object msg)
  {
	  Vector<String[]> result=(Vector<String[]>)msg; 
	  Vector<String> Classes=new Vector<String>();
	 
	  for(int i=1;i<result.size();i++)
	  {
		  String[] array = (String[])result.get(i);
		  Classes.add(array[0]);
		 
	  }
	  lg.getAdminMenu().setClassesForStudAtt(Classes);
	  lg.getPrincipleMainMenu().setClassesPrinciple(Classes);
  }
  public void updateUnattStud(Object msg)
  {
	  Vector<String[]> result=(Vector<String[]>)msg;
	  Vector<StudentClass> StudResult=new Vector<StudentClass>();//sid,FirstName,LastName
	  
	  if (result.isEmpty())
		  lg.getAdminMenu().setStudentsForStudAtt(StudResult);
	  else
		  {
		  System.out.println("\n not empty "+result.get(result.size()-1)[0]);
		  for(int i=1;i<result.size()-1;i++)
		  {
			  String[] array = (String[])result.get(i);
			  StudResult.add(new StudentClass(array[1],array[2],array[0]));//FirstName,LastName,sid
			 
		  }
		  lg.getAdminMenu().setStudentsForStudAtt(StudResult);
	  }
  }
  
  public void updateRawCoursesToAdmin(Object msg)
  {
	  Vector<String[]> result=(Vector<String[]>)msg;
	  Vector<RawCourse> Courses=new Vector<RawCourse>();
	  for(int i=0;i<result.size()-1;i++)
	  {
		  String[] array = (String[])result.get(i);
		  Courses.add(new RawCourse(array[0],array[1],array[2],array[3]));
		 
	  }
	  lg.getAdminMenu().setRawCoursesForClassAtt(Courses);
	  
  }
  public void updateCoursesAdminForExQuery(Object msg)
  {
	  Vector<String[]> result=(Vector<String[]>)msg;
	  Vector<RawCourse> Courses=new Vector<RawCourse>();
	  for(int i=0;i<result.size()-1;i++)
	  {
		  String[] array = (String[])result.get(i);
		  Courses.add(new RawCourse(array[0],array[1],array[2],array[3],array[4]));
		 
	  }
	  lg.getAdminMenu().setRawCoursesAdminForExQuery(Courses);
	  
  }
  
  public void updateTeachersToAdmin(Object msg)
  {
	  Vector<String[]> result=(Vector<String[]>)msg;
	  Vector<TeacherClass> Teachers=new Vector<TeacherClass>();
	  for(int i=0;i<result.size()-1;i++)
	  {
		  String[] array=result.get(i);
		  Teachers.add(new TeacherClass(array[0],array[1],array[2],array[3],array[4],array[5]));
		  
	  }
	  lg.getAdminMenu().setTeachersForClassAtt(Teachers);
	 
  }
  public void updateTeachersForHisPrinciple(Object msg)
  {
	  Vector<String[]> result=(Vector<String[]>)msg;
	  Vector<TeacherClass> Teachers=new Vector<TeacherClass>();
	  for(int i=0;i<result.size()-1;i++)
	  {
		  String[] array=result.get(i);
		  Teachers.add(new TeacherClass(array[0],array[1],array[2],array[3],array[4]));
		  
	  }
	 
	  lg.getPrincipleMainMenu().setTeachersForHisPrinciple(Teachers);
  }
  public void updateStudentsForEx(Object msg)
  {
	  Vector<String[]> result=(Vector<String[]>)msg;
	  Vector<StudentClass> Students=new Vector<StudentClass>();
	  for(int i=0;i<result.size()-1;i++)
	  {
		  String[] array=result.get(i);
		  Students.add(new StudentClass(array[1],array[2],array[0],array[3]));
	
	  }
	  lg.getAdminMenu().setStudentsForEx(Students);
  }
  public void updateStudentCoursesForEx(Object msg)
  {

	  Vector<Course> CourseResult=new Vector<Course>();
	
	  
	  Vector<String[]> result=(Vector<String[]>)msg;
	  Vector<String> ids=new Vector<String>();
	  for (int i=0; i<result.size()-1; i++){
			String[] array = (String[])result.get(i);
			
		CourseResult.addElement(new Course(array[0],array[1],array[2],array[3],array[4],array[5]));
		ids.add(array[6]);
		System.out.println("\n in updateCoursesInfoStudent to Admin sid is"+ array[5]+" course"+array[0]);
		
		}
	 

	  System.out.println("\n in updateCoursesInfoAdmin size "+ CourseResult.size());
	  lg.getAdminMenu().setStudentCoursesForEx(CourseResult,ids);
	 
	
	  
		 
  }public void updateStudentCoursesForAddEx(Object msg)
  {

	  Vector<Course> CourseResult=new Vector<Course>();
	
	  
	  Vector<String[]> result=(Vector<String[]>)msg;
	  Vector<String> ids=new Vector<String>();
	  for (int i=0; i<result.size()-1; i++){
			String[] array = (String[])result.get(i);
			
		CourseResult.addElement(new Course(array[0],array[1],array[2],array[3],array[4],"false",array[5]));
		ids.add(array[5]);
		System.out.println("\n in updateStudentCoursesForAddEx to Admin sid is"+ array[5]+" course"+array[0]);
		
		}
	 

	  System.out.println("\n in updateStudentCoursesForAddEx size "+ CourseResult.size());
	  lg.getAdminMenu().setStudentCoursesForEx(CourseResult,ids);
	 
	
	  
		 
  }
  public void updateStudentCoursesForRemEx(Object msg)
  {

	  Vector<Course> CourseResult=new Vector<Course>();
	
	  
	  Vector<String[]> result=(Vector<String[]>)msg;
	  Vector<String> ids=new Vector<String>();
	  for (int i=0; i<result.size()-1; i++){
			String[] array = (String[])result.get(i);
			
		CourseResult.addElement(new Course(array[0],array[1],array[2],array[3],array[4],"false",array[5]));
		ids.add(array[5]);
		System.out.println("\n in updateStudentCoursesForRemEx to Admin sid is"+ array[5]+" course"+array[0]);
		
		}
	 

	  System.out.println("\n in updateCoursesInfoAdmin size "+ CourseResult.size());
	  lg.getAdminMenu().setStudentCoursesForEx(CourseResult,ids);
	 
	
	  
		 
  }
  public void updateClassesCoursesForEx (Object msg)
  {
	  Vector<String[]> result=(Vector<String[]>)msg;
	  Vector<CourseOfClass> c=new Vector<CourseOfClass>();
	  CourseOfClass temp;
	  System.out.println("in updateClassesCoursesForEx ");
	  for (int i=0; i<result.size()-1; i++){
		  String[] array = (String[])result.get(i);
		  System.out.println("size array: "+ array.length);
		  System.out.println("in updateClassesCoursesForEx of"+array[0]+" "+array[1]+" "

				  +array[2]+" "+array[3]+" "+array[4]+" "+array[5]+" "+array[6]+" "+array[7] );
		  temp=new CourseOfClass(array[0],array[1],array[2],array[3],array[4],array[5],array[6],array[7]) ;
		  c.add(temp);
		  
	  }
	  lg.getAdminMenu().setClassesCoursesForEx(c);
  }
  
  public void updateParentsToManagment(Object msg)
  {
	  Vector<String[]> result=(Vector<String[]>)msg;
	  Vector<ParentClass> p=new Vector<ParentClass>();
	  ParentClass temp;
	  System.out.println("in updateParentsToManagment ");
	  if(result.size()>1)
	  {
		  for (int i=0; i<result.size()-1; i++){
			  String[] array = (String[])result.get(i);
			  temp=new ParentClass(array[0],array[1],array[2],array[3]);
			 
			  p.add(temp);
			  System.out.println("in updateParentsToManagment of"+array[0]+" "+array[1]+" "
	
					 );
		  }
	
	  }
	  else  System.out.println("in updateParentsToManagment is empty ");
	  lg.setParentalBlockData(p);
	  lg.getManagmentMainMenu().setParents(p);
	  
  }
  public void updateStudCoursesForAtt(Object msg)
  {
	  Vector<String[]> result=(Vector<String[]>)msg;
	  Vector<CourseOfStudent> c=new Vector<CourseOfStudent>();
	  CourseOfStudent temp;
	  for (int i=0; i<result.size()-1; i++){
		  String[] array = (String[])result.get(i);
		  temp=new CourseOfStudent(array[0],array[1],array[2],array[3],array[4],array[5],array[6],array[7],array[8]);
		  c.add(temp);
		  System.out.println("in updateStudCoursesForAtt of"+temp.getSid()+" "+array[1]+" "+
		  array[2]+" "+array[3]+" "+array[4]+" "+array[5]+" "+array[6]+" "+array[7]+" "+array[8]);
	  
	  }
	  lg.getAdminMenu().setCoursesOfStudOfClass(c);
  }
  public void updatePreCoursesForAtt(Object msg)
  {
	  Vector<String[]> result=(Vector<String[]>)msg;
	  Vector<String[]> c=new Vector<String[]>();
	 // String[] temp;
	  for (int i=0; i<result.size()-1; i++){
		  String[] array = (String[])result.get(i);
		 
		  c.add(array);
		  System.out.println("in updatePreCoursesForAtt of"+array[0]+" "+array[1]);
	  
	  }
	  lg.getAdminMenu().setPreCoursesForAtt(c);
  }
  public void updateStudentWithClassesForAtt(Object msg)
  {
	  Vector<String[]> result=(Vector<String[]>)msg;
	  Vector<StudentClass> s=new Vector<StudentClass>();
	 
	  for (int i=0; i<result.size()-1; i++){
		  String[] array = (String[])result.get(i);
		 
		 
		  s.add(new StudentClass(array[1],array[2],array[0],array[3]));
		  System.out.println("in updateStudentWithClassesForAtt of"+array[0]+" "+array[1]);
	  
	  }
	  lg.getAdminMenu().setStudentsWithClasses(s);
  }
  public void returnResultAttStudAndClassToCourse(Object msg)
  {
	  Vector<String[]> result=(Vector<String[]>)msg;
	  boolean approval=false;
	  
	  if(result.get(0)[0].equalsIgnoreCase("AttributeStudentsToCourse"))
		  approval=true;
	 
	  
		  System.out.println("\nin returnResultAttStudAndClassToCourse ");
	  
	 
	  lg.getAdminMenu().setResultAttStudAndClassToCourse(approval);
  }
  public void returnAppToLockSemester(Object msg)
  {
	  Vector<String[]> result=(Vector<String[]>)msg;
	  boolean approval=false;
	  
	  if(result.get(0)[0].equalsIgnoreCase("UpdateLockToCurrentSemester"))
		  approval=true;
	 
	  
		  System.out.println("\nin returnAppToLockSemester ");
	  
	 
	  lg.getAdminMenu().setreturnAppToLockSemester(approval);
  }
  public void returnAppToCreateExReqStudRem(Object msg)
  {
	 
	  boolean approval=true;
		
	  
	  
		  System.out.println("\nin returnAppToCreateExReqStudRem ");
	  
	 
	  lg.getAdminMenu().setAppToCreateExReqStudRem(approval);
  }
  public void returnAppInsertStudentToClass(Object msg)
  {
	 
	  boolean approval=true;
		
	  
	  
	System.out.println("\nin returnAppInsertStudentToClass ");
	  
	 
	  lg.getAdminMenu().setAppInsertStudentToClass(approval);
  }
  public void updateDataHistBetweenTeachersInChosenClass(Object msg)
  {
	  Vector<String[]> result=(Vector<String[]>)msg;
	  Vector<BetweenTeachersChClass> a=new Vector<BetweenTeachersChClass>();
	  
	  for(int i=0;i<result.size()-1;i++)
	  {
		  String[] array=result.get(i);
		  a.add(new BetweenTeachersChClass(array[0],array[1],array[2]));
		 
		  
	  }
	 
	  
		  
	  
	 
	  lg.getPrincipleMainMenu().setDataHistBetweenTeachersInChosenClass(a);
  }
  public void updateDataForHistBetweenClassesToChosenTeacher(Object msg)
  {
	  Vector<String[]> result=(Vector<String[]>)msg;
	  Vector<BetweenClassesChTeacher> a=new Vector<BetweenClassesChTeacher>();
	  System.out.println("\nin updateDataForHistBetweenClassesToChosenTeacher "+result.size());
	  for(int i=0;i<result.size()-1;i++)
	  {
		  String[] array=result.get(i);
		  System.out.println("\nin updateDataForHistBetweenClassesToChosenTeacher "+array[0]+" "+array[1]);
		  a.add(new BetweenClassesChTeacher(array[0],array[1]));
		  
	  }
	 
	  
		  System.out.println("\nin updateDataForHistBetweenClassesToChosenTeacher ");
	  
	 
	  lg.getPrincipleMainMenu().setDataForHistBetweenClassesToChosenTeacher(a);
  }
  public void updateDataForHistBetweenCoursesToChosenClass(Object msg)
  {
	  Vector<String[]> result=(Vector<String[]>)msg;
	  Vector<BetweenCoursesToClass> a=new Vector<BetweenCoursesToClass>();
	  
	  for(int i=0;i<result.size()-1;i++)
	  {
		  String[] array=result.get(i);
		  a.add(new BetweenCoursesToClass(array[0],array[1]));
		  
	  }
	 
	  
		  System.out.println("\nin updateDataForHistBetweenCoursesToChosenClass ");
	  
	 
	  lg.getPrincipleMainMenu().setDataForHistBetweenCoursesToChosenClass(a);
  }
  public void updateCoursesOfClass (Object msg)
  {
	  Vector<String[]> result=(Vector<String[]>)msg;
	  Vector<CourseOfClass> c=new Vector<CourseOfClass>();
	  CourseOfClass temp;
	  System.out.println("in updateCoursesOfClass ");
	  for (int i=0; i<result.size()-1; i++){
		  String[] array = (String[])result.get(i);
		  
		  temp=new CourseOfClass(array[0],array[1]);
		  c.add(temp);
		  
	  }
	  lg.getAdminMenu().setCoursesOfClass(c);
  }
  public void updateDesExReqAddStudToCourse()
  {
	 
	  boolean approval=true;
		
	  
	  
	System.out.println("\nin returnAppInsertStudentToClass ");
	  
	 
	  lg.getPrincipleMainMenu().setDesExReqAddStudToCourse(approval);
  }
  public void updateApproveToNewClass()
  {
	 
	  boolean approval=true;
		
	  
	  
	
	  
	 
	  lg.getAdminMenu().setApproveToNewClass(approval);
  }
  public void updateApproveToNewSemester()
  {
	 
	  boolean approval=true;
		
	  
	  
	System.out.println("\nin returnAppInsertStudentToClass ");
	  
	 
	  lg.getAdminMenu().setApproveToNewSemester(approval);
  }
  public void updateApproveToParentalBlock()
  {
	 
	  boolean approval=true;
		
	  
	  
	System.out.println("\nin updateApproveToParentalBlock ");
	  
	 
	  lg.getManagmentMainMenu().updateApproveToParentalBlock(approval);
  }

 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
  //saving all the data that we need for viewing New Assignment Details 
  public void NewAssignmentScreenData(HashMap<String, Object> msg)
  {
	 System.out.println("IN ClientConsol NewAssignmentScreenData\n");

      lg.getStudentMainMenu().setTaskNume((String)msg.get("taskNum"));
      
      lg.getStudentMainMenu().setDeadLine((String)msg.get("deadLine"));
      
      lg.getStudentMainMenu().setMyByteArr((byte[])msg.get("mybytearr"));
    
  }
  
  
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//=======
  public void updateExReqTeacherRepQuery (Object msg)
  {
	  Vector<String[]> result=(Vector<String[]>)msg;
	  Vector<DataForExPrincipleReplaceTeacher> c=new Vector<DataForExPrincipleReplaceTeacher>();
	  DataForExPrincipleReplaceTeacher temp;
	  System.out.println("in updateExReqTeacherRepQuery ");
	  for (int i=0; i<result.size()-1; i++){
		  String[] array = (String[])result.get(i);
		  
		  temp=new DataForExPrincipleReplaceTeacher(array[0],array[1],array[2]+" "+array[3],array[4],array[5],array[6],array[7],array[8]+" "+array[9]);
		  c.add(temp);
		  
	  }
	  lg.getPrincipleMainMenu().setExReqTeacherRepQuery(c);
  }

  
  public void updateExReqStudAddQuery (Object msg)
  {
	  Vector<String[]> result=(Vector<String[]>)msg;
	  Vector<DataForExPrincipleAddStudToCorse> c=new Vector<DataForExPrincipleAddStudToCorse>();
	  DataForExPrincipleAddStudToCorse temp;
	  System.out.println("in updateExReqStudAddQuery ");
	  for (int i=0; i<result.size()-1; i++){
		  String[] array = (String[])result.get(i);
		  
		  temp=new DataForExPrincipleAddStudToCorse(array[0],array[1],array[2]+" "+array[3],array[4],array[5],array[6]);
		  c.add(temp);
		  
	  }
	  lg.getPrincipleMainMenu().setExReqStudAddQuery(c);
  }
  public void updateExReqStudRemQuery (Object msg)
  {
	  Vector<String[]> result=(Vector<String[]>)msg;
	  Vector<DataForExPrincipleRemoveStudFromCourse> c=new Vector<DataForExPrincipleRemoveStudFromCourse>();
	  DataForExPrincipleRemoveStudFromCourse temp;
	  System.out.println("in updateExReqStudRemQuery size"+result.size() );
	  for (int i=0; i<result.size()-1; i++){
		  String[] array = (String[])result.get(i);
		  
		  temp=new DataForExPrincipleRemoveStudFromCourse(array[0],array[1],array[2]+" "+array[3],array[4],array[5]);
		  System.out.println("in updateExReqStudRemQuery "+ temp.Sid);
		  c.add(temp);
		  
	  }
	  lg.getPrincipleMainMenu().setExReqStudRemQuery(c);
  }

  //Class methods ***************************************************
  
  /**
   * This method is responsible for the creation of the Client UI.
   *
   * @param args[0] The host to connect to.
   */
  public static void main(String[] args) 
  {
    
	  
	String host = "";
    int port = 0;  //The port number
    System.out.println("\n Welcome! please enter server name or press ENTER for localhost:");
    
    InputStreamReader input = new InputStreamReader(System.in);
    BufferedReader reader = new BufferedReader(input);
    
    try {
		host=reader.readLine();
		if(host.equalsIgnoreCase(""))
		{
			System.out.println("host is localhost");
			host = "localhost";
			
		}
		
	} catch (IOException e1) {
		
		e1.printStackTrace();
	}

    
   
    ClientConsole chat= new ClientConsole(host, DEFAULT_PORT);
   // System.out.println("Test1");
    //   chat.accept();  //Wait for console data
    chat.lg=new Login();
    chat.us=new UserStudent();
    // Login loginFrame=new Login();
   // Login.setChat();
    lg.setChat(chat.client);
	lg.setSize(300,300);
	lg.setVisible(true);
	//lg.setText("Done");
	//Student.conStatus="login ok";  
	//StudentClass student=new StudentClass(chat.client,"Yossi","Biton","106","1234");
    //GUI.Login.main(host, port);
  }
}
//End of ConsoleChat class
